namespace JQuery.WebKit
{
    using System;

    internal class Searching : BaseSearching
    {
        private WebGrid _grid;
        private string _searchColunm;
        private string _searchOperation;
        private string _searchString;

        public Searching(WebGrid grid, string searchColumn, string searchString, string searchOperation)
            : base(grid)
        {
            this._grid = grid;
            this._searchColunm = searchColumn;
            this._searchString = searchString;
            this._searchOperation = searchOperation;
        }

        public SearchCriteriaCollection PerformSearch(string search)
        {
            if (!string.IsNullOrEmpty(search) && Convert.ToBoolean(search))
            {
                WebGridSearchEventArgs e = new WebGridSearchEventArgs();
                SearchCriteria criteria = new SearchCriteria(this._searchColunm, this._searchString, base.GetSearchOperationFromString(this._searchOperation));
                e.CriteriaList.Add(criteria);

                this._grid.OnSearching(e);
                if (e.Cancel)
                {
                    return null;
                }
                this._grid.OnSearched(new EventArgs());
                return e.CriteriaList;
            }
            return null;
        }
    }
}

